﻿using System;
using System.IO;
using DotVVM.Framework.Configuration;
using DotVVM.Framework.ResourceManagement;
using DotVVM.Framework.Routing;
using DotVVM.Framework.Storage;
using Microsoft.Extensions.DependencyInjection;

namespace VOICeVIO.Hybrid
{
    public class DotvvmStartup : IDotvvmStartup
    {
        // For more information about this class, visit https://dotvvm.com/docs/tutorials/basics-project-structure
        public void Configure(DotvvmConfiguration config, string applicationPath)
        {
            config.AddBusinessPackConfiguration();
            ConfigureRoutes(config, applicationPath);
            ConfigureControls(config, applicationPath);
            ConfigureResources(config, applicationPath);
        }

        private void ConfigureRoutes(DotvvmConfiguration config, string applicationPath)
        {
            config.RouteTable.Add("Default", "", "Views/default.dothtml");
            config.RouteTable.Add("About", "about", "Views/About.dothtml");
            config.RouteTable.Add("Download", "download/{Id}/{Name}", "Views/Download.dothtml");
            config.RouteTable.Add("Create", "create", "Views/Create.dothtml");
            //config.RouteTable.Add("CRUD_Detail", "detail/{Id}", "Views/CRUD/Detail.dothtml");
            //config.RouteTable.Add("CRUD_Edit", "edit/{Id}", "Views/CRUD/Edit.dothtml");
            config.RouteTable.AutoDiscoverRoutes(new DefaultRouteStrategy(config));
        }

        private void ConfigureControls(DotvvmConfiguration config, string applicationPath)
        {
            // register code-only controls and markup controls
        }

        private void ConfigureResources(DotvvmConfiguration config, string applicationPath)
        {
            // register custom resources and adjust paths to the built-in resources
            config.Resources.Register("bootstrap-css", new StylesheetResource
            {
                Location = new UrlResourceLocation("~/lib/bootstrap/dist/css/bootstrap.min.css")
            });
            config.Resources.Register("bootstrap-theme", new StylesheetResource
            {
                Location = new UrlResourceLocation("~/lib/bootstrap/dist/css/bootstrap-theme.min.css"),
                Dependencies = new[] { "bootstrap-css" }
            });
            config.Resources.Register("bootstrap", new ScriptResource
            {
                Location = new UrlResourceLocation("~/lib/bootstrap/dist/js/bootstrap.min.js"),
                Dependencies = new[] { "bootstrap-css", "jquery" }
            });
            config.Resources.Register("jquery", new ScriptResource
            {
                Location = new UrlResourceLocation("~/lib/jquery/dist/jquery.min.js")
            });
            config.Resources.Register("Styles", new StylesheetResource()
            {
                Location = new UrlResourceLocation("~/styles.css")
            });
            config.Resources.Register("StylesEx", new StylesheetResource()
            {
                Location = new UrlResourceLocation("~/StylesEx.css")
            });
            config.Resources.Register("Override", new StylesheetResource()
            {
                Location = new UrlResourceLocation("~/override.css")
            });
        }

        //public void ConfigureServices(IDotvvmServiceCollection services)
        //{
        //    services.AddDefaultTempStorages("Temp");
        //}
    }
}
